<?php

    /**
     *      [Discuz!] (C)2001-2099 Comsenz Inc.
     *      This is NOT a freeware, use is subject to license terms
     *      $Id: table_mobile_setting.php 31281 2012-08-03 02:29:27Z zhangjie $
     */

    if (!defined('IN_DISCUZ')) {
        exit('Access Denied');
    }

    class table_cloud_product_photo extends discuz_table {

        public function __construct() {
            $this->_table = 'cloud_product_photo';
            $this->_pk = 'cppid';

            parent::__construct();
        }

        //插入数据库
        public function insert($arr) {
            return DB::insert($this->_table, $arr, true);
        }

        //更新数据库
        public function update($id, $data) {
            $id = intval($id);
            if (!$data) {
                return;
            }
            return DB::update($this->_table, $data, DB::field($this->_pk, $id));
        }

        //查找某条记录
        public function fetch_info($id) {
            $id = intval($id);
            return DB::fetch_first("SELECT * FROM %t WHERE " . $this->_pk . "=%d", array($this->_table, $id));
        }

        // 得到单个图片
        public function fetch_info_photo($cpid, $cppid) {
            return DB::fetch_first("SELECT * FROM %t WHERE cpid =%d and cppid =%d ", array($this->_table, $cpid, $cppid));
        }

        //查询所有limt数据
        public function fetch_all_limit($cpid, $start = 0, $limit = 0) {
            return DB::fetch_all('SELECT * FROM ' . DB::table($this->_table) . ' where cpid=' . $cpid . ' order by ' . DB::order('lasttime', 'desc') . DB::limit($start, $limit));
        }

        //查询所有limt数据
        public function fetch_all_by_product($cpid) {
            return DB::fetch_all('SELECT * FROM ' . DB::table($this->_table) . ' where cpid=' . $cpid . ' order by ' . DB::order('display').', '. DB::order('lasttime', 'desc'));
        }

        // 删除
        public function delete_by_id($id) {
            return DB::query("DELETE FROM %t WHERE cppid =%d", array($this->_table, $id));
        }

        // 更新产品图片ID
        public function update_product_pic($id, $data) {
            return DB::query("UPDATE FROM " . $this->_table . " SET cpid = " . $id . " WHERE cppid in(" . $data . ")");
        }
        //是否存在
        public function search_display($cpid,$display) {
            $cpid = intval($cpid);
            return DB::fetch_first('SELECT cppid FROM '.DB::table($this->_table).' WHERE cpid=' . $cpid.' and display='.$display);
        }

    }